The computer (microprocessor) is an invention that greatly influences daily living of human beings. Many products, even as tiny as the core of a digital watch, are configured with one or more microprocessors, or configured with a microcontroller containing a microprocessor. At present, the mainstream large computer has 64-bit microcontroller and mainstream small computer has 8-bit microcontroller.
Both large computers and small computers operate according to programs written by programmers. Theoretically, a microprocessor can only process one program in one moment. However, a computer can seemingly process several programs simultaneously in the same period via the interruption mechanism provided by the hardware and the time-sharing mechanism provided by the operating system, or via a plurality of sub-task blocks divided by the programmer and executed segmentedly. Such a technology is so-called “multitasking”.
In a multitasking computer system, many tasks simultaneously share the operation resources of the computer. If the operation resource sharing is not appropriately controlled, a certain task cannot be finished within a period of validity or never finished; for example, the second hand of the digital watch cannot be updated each second. The requirement for finishing a task within a period of time is called “real-time task”.
In order to process many tasks simultaneously with a single microprocessor, all the programs executed simultaneously in a computer have to be divided into a plurality of sub-task blocks, and each sub-task block should not occupy too long an execution time lest other programs sharing the resources of the computer cannot be executed timely. After a program has been divided into many sub-task blocks, the sub-task blocks must be controlled to be executed sequentially one after one, and the sub-task blocks of other programs are allowed to be interposed and executed during transition of the sub-task blocks in the same program.
Therefore, a multitasking mechanism at least comprises four mechanisms of division, register, scheduling and execution. Each program can be divided into many sub-task blocks. Each sub-task block will register an execution demand for the succeeding sub-task block. The scheduling mechanism arranges the execution sequence for the registered execution demands. Finally, the sub-task blocks are executed according to the execution sequence.
Traditionally, the aforesaid four mechanisms are divided by the programmer according to the execution stages of the program. After divided, the succeeding program block is established an enable flag before the preceding program block is finished to complete register of an execution demand. The scheduling is implemented by a polling mechanism, which alternately searches the execution-demand flags of all the sub-task blocks possibly needing execution. The first sub-task block having execution demand in polling will be executed firstly.
The abovementioned approach that the programmer processes by himself has three primary problems: 1. an optimized division only can be achieved by requiring a sophisticated programmer; 2. the greater number of the sub-task blocks, the more execution time consumed in polling; 3. the scheduling is random, such that the execution timing is unstable.
The current operating system aims to solve the first problem with the second problem being improved by the way. The current operating system is derived from the concept of time-sharing and multitasking, where a core program of the operating system is added to control operation of other programs in addition to the application program. The core program of the operating system is triggered and executed by timing interruption. The work of the core program includes dividing and examining the currently executed task, registering the programs having execution demands, determining whether to interrupt the task that is being executed according to the predetermined priority sequence, and determining which task will be executed next, which belong to the scheduling mechanism thereof. When switching tasks being needed, the interrupted task is registered in the execution-standby queue and arranges to execute new tasks while leaving the core program. Thereby, the operating system takes charge of the four mechanisms required by a multitasking system—division, register, scheduling and execution, and exempts programmers from the burden of handling the four mechanisms by himself. As the division mechanism handled by the operating system, the sections that have been executed are eliminated automatically while the sections that have not been executed needn't to perform polling. Therefore, the tasks needed to be polled are limited by the number of the programs which are executed simultaneously without greatly increasing caused by division of program. Thus is improved the abovementioned second problem of more polling burden. However, the problem of randomly selecting the registered tasks still exists if scheduling of the operating system is undertaken in a polling way.
Using an operating system indeed solves some problems, but the system also pays some cost for it. Firstly, as the operating system itself is also a program and occupies some operation resources while executing, the system has to pay extra cost in operation time. As the operating system divides a program by timing, it cannot predict which part of the program is to be divided. In order to protect the data in the preceding section and the succeeding section does not be changed, the operating system has to temporarily store all the variables in the program that have been interrupted being transferred from a flash memory to a slower memory, and transfers the preceding stored variables in the program that will be executed from the slower memory to the flash memory. Such an action is called “context switch”. Context switch not only consumes extra operation time but also occupies much extra memory space. This problem is generated accompanying the action that the operating system divides a program by timing.
An ordinary operating system does not concern the real time. However, in some industrial applications, such as automatic control and instrumental measurement, real-time performance is highly demanded. The real-time demand will not be satisfied unless the random execution caused by polling is overcome. A real time operating system (RTOS) has been developed to solve the real-time problem for industrial computers. In a time-sharing and multitasking operating system, if the frequency of core execution and division in the operating system can be increased to the period of real-time task, it can provide new register and execution opportunity for a task having real-time demand. Besides, the problem of random execution caused by polling of the execution-standby tasks has to be overcome or reduced. Thus, the priorities can be separated for different execution-standby tasks to reduce and limit the number of the tasks to be polled. Thereby, the uncertainty of polling and random selection of the execution-standby tasks can be decreased, and the real-time demand is more likely to be satisfied.
Increasing the frequency of the scheduling and core execution in the operating system indeed creates the possibility that the real time is scheduled into the period, but extra execution time occupied by core execution in the operating system and extra execution time of transferring data between different memories in context switch also are doubled.
If the operation capability of the computer system is not so high, the operating system will occupy much more execution time than other application programs, especially in a real-time operating system. Therefore, a great majority of operating system is used in a larger computer (at least a PC rank computer). An 8-bit or 16-bit microcontroller/digital signal processor (DSP) seldom adopts a multitasking operating system to execute scheduling. Even if the computer adopts the multitasking operating system, it usually is used to reduce the ratio that the operating system occupying the extra execution time by removing the context switch mechanism but adopting a wide-area fixed memory instead.
No matter whether scheduling is performed by the programmer himself or by the scheduler of the operating system, the problem of random selection always appears as long as scheduling is implemented via polling and searching the flags of registered execution demands. In these cases, the uncertainty of real-time performance increases.
According to the above conventional technologies, a simple and fast scheduler, which has fixed scheduling to occupy extra execution time, is absent to provide a stable and real-time scheduling function.